//
//  UIImageViewExtension.swift
//  DragonWallet
//
//  Created by volantPig on 2024/8/19.
//

import UIKit

class UIImageViewExtension: NSObject {

}

extension UIImageView {
    func downloadImage(_ imageKey: String,_ placeholder: String = "loading_placeholder") {
        var params = [String: Any]()
        params["imageKey"] = imageKey
//        "32956d2276c33b3a71be8ffcd8fdc1db25262f005eda9a392ff007a6520d1681"
        JDDataNetWorkRequest(.downloadImage(params)) { responseData in
            printLog("获取图片成功:\(responseData)")
            
            if responseData.count == 0 {
                self.backgroundColor = .commonColor()
                self.image = UIImage(named: placeholder)?.withRenderingMode(.alwaysOriginal)
                return;
            }
            
            let dataImage = UIImage(data: responseData)
            self.image = dataImage
        } failure: { error in
            printLog("获取图片失败")
        } error: { errorCode in
            printLog("获取图片错误Code:\(errorCode)")
        }
    }
}
